package com.bingquan.company.test;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

public interface FuncInterface {
    // An abstract function
    void abstractFun(int x);

    // A non-abstract (or default) function
    default void normalFun() {
        System.out.println("Hello");
    }
}

class Test {
    public static void main(String args[]) {
        // lambda expression to implement above
        // functional interface. This interface
        // by default implements abstractFun()
        FuncInterface fobj = (int x) -> System.out.println(2 * x);

        // This calls above lambda expression and prints 10.
        fobj.abstractFun(5);
    }


}

class ConsumerFunctionExample {
    public static void main(String args[]) {
        // 定义个larmda表达式，实现consumer函数接口中唯一的抽象方法
        Consumer<Integer> consumer = i -> System.out.print(" " + i);
        // 调用andThen方法，理解： andThen方法入参是Consumer匿名实现类
        Consumer<Integer> consumerWithAndThen = consumer.andThen(i -> System.out.print("(printed " + i + ")"));
        List<Integer> integerList =
                Arrays.asList(new Integer(1), new Integer(10), new Integer(200), new Integer(101),
                        new Integer(-10), new Integer(0));
        printList(integerList, consumerWithAndThen);
    }

    public static void printList(List<Integer> listOfIntegers, Consumer<Integer> consumer) {
        for (Integer integer : listOfIntegers) {
            consumer.accept(integer);
        }
    }
}
